import { AsyncData, UseFetchOptions } from "#app";

interface RequestConfig<DataT = any> extends UseFetchOptions<DataT> {

}

class Request {
  private readonly options

  constructor (options: RequestConfig ) {
    this.options = options
  }

  async request<T>(url:string,options: RequestConfig):Promise<AsyncData<T,Error | null>>{
    return useFetch(url,Object.assign(options,this.options))
  }

  get<T>(url:string,options: RequestConfig) {
    return this.request<T>(url,{...options,method:'GET'});
  }

  post<T>(url:string,options: RequestConfig) {
    return this.request<T>(url,{...options,method:'POST'});
  }
}

export const request = new Request({
  baseURL:'http://codercba.com:9060/oppo-nuxt/api'
})
